package com.sgb.kjwl.viewmodel.self.driver;

import android.app.Application;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.self.MotorcadeSimpleEntity;
import com.sgb.kjwl.model.entity.self.VerifyDriverEntity;
import com.sgb.kjwl.model.response.ListResponse2;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Describe:
 * Author:  yangLei
 * Date:    2021/10/12
 */
public class AddProDriverModel extends BaseViewModel {
    public MutableLiveData<List<MotorcadeSimpleEntity>> motorcadeListLD = new MutableLiveData<>();
    public MutableLiveData<VerifyDriverEntity> driverLD = new MutableLiveData<>();
    public MutableLiveData<Boolean> addLD = new MutableLiveData<>();

    public AddProDriverModel(@NonNull @NotNull Application application) {
        super(application);
    }

    /**
     * 请求自营车队列表
     */
    public void requestMotorcadeList(Context context) {
        DialogHelper.showProgressDialog(context, "请求中...");
        Map<String, Object> map = new HashMap<>();
        map.put("type", 1);//合作类型 1 自营 2 挂靠
        map.put("page", 1);
        map.put("limit", 99);
        NewAPIManager.getInstance().getLogisticsAPI().getMotorcadeList(map).enqueue(new ICallBack<BaseEntity<ListResponse2<List<MotorcadeSimpleEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse2<List<MotorcadeSimpleEntity>>> data) {
                if (data != null) {
                    if (data.getData() != null) {
                        motorcadeListLD.postValue(data.getData().getList());
                    } else {
                        motorcadeListLD.postValue(null);
                    }
                }
            }
        });
    }

    /**
     * 根据手机号搜索司机（自营司机添加判断）
     */
    public void searchDriverByPhone(Context context, String num) {
        DialogHelper.showProgressDialog(context, "请求中...");
        NewAPIManager.getInstance().getLogisticsAPI().verifyDriverByPhone(num).enqueue(new ICallBack<BaseEntity<VerifyDriverEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VerifyDriverEntity> data) {
                if (data.getData()!=null){
                    driverLD.postValue(data.getData());
                }
            }
        });
    }

    /**
     * 新添加自营司机到团队
     */
    public void newAddDriver(Context context,String no) {
        DialogHelper.showProgressDialog(context, "请求中...");
        Map<String, Object> map = new HashMap<>();
        map.put("driverNo", no);
        map.put("type", 1);
        NewAPIManager.getInstance().getLogisticsAPI().newAddProDriver(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                MToast.showToast(context.getApplicationContext(), "添加成功");
                addLD.postValue(true);
            }
        });
    }

}
